package com.summer.data.jql.compose;

import com.summer.data.Jsql;
import com.summer.data.dialect.Dialect;
import com.summer.data.jql.Context;
import com.summer.data.jql.behavior.SelectAble;
import com.summer.data.jql.concept.Field;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 多个字段，中间用 [,] 分开
 * 
 * @author 345480567@qq.com
 */
public class FieldPack implements SelectAble {

    List<Field<?>> fieldList = new ArrayList<>();

    public FieldPack(Field<?>... exps) {
        Collections.addAll(fieldList, exps);
    }

    public FieldPack(List<Field<?>> fieldList) {
        this.fieldList.addAll(fieldList);
    }

    @Override
    public Jsql toSelectJsql(Context ctx, Dialect dialect) {
        Jsql jsql = new Jsql();
        for (int i = 0; i < fieldList.size(); i++) {
            if (i != 0) {
                jsql.append(", ");
            }
            jsql.append(fieldList.get(i).toSelectJsql(ctx, dialect));
        }
        return jsql;
    }
}
